from OpenGL.GL import *
from OpenGL.GLUT import *
import sys, math

LENGTH = 6

def initGL(width, height):
    # Set bg color to blue
    glClearColor(0.0, 0.0, 1.0, 0.0)
    # Set orthographic projection
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    # kamera position left, right, bottom, top, near, far
    glOrtho(-10, 10, -10, 10,  -1.0, 1.0)
    glMatrixMode(GL_MODELVIEW)
    #glEnable(GL_LIGHTING)
    #glEnable(GL_LIGHT0)

def display():
    print 'display'
    # Clear framebuffer
    glClear(GL_COLOR_BUFFER_BIT)
    # Set color to light gray
    glColor3f(.75, .75, .75)
    # Set drawstyle
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    # Set primitve type to polygon
    glBegin(GL_TRIANGLES)

    
    for i in range(LENGTH):
        glVertex2f(-6+i, 2*((i+1)%2 * -1))
        glVertex2f(-5+i, 2*(i%2 * -1))
        glVertex2f(-4+i, 2*((i+1)%2 * -1))

    for i in range(LENGTH):
        glVertex2f(6-i, 2*((i+1)%2))
        glVertex2f(5-i, 2*(i%2))
        glVertex2f(4-i, 2*((i+1)%2))
    
    glEnd()
    # Flush commands
    glFlush()

def main():
    print 'main'
    # Initialize GLUT
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutInitWindowSize(500, 500)
    glutCreateWindow("Einfaches OpenGL-Programm")
    # Register display callback function
    glutDisplayFunc(display)
    # Initialize OpenGL context
    initGL(500, 500)
    # Start GLUT mainloop
    glutMainLoop()

if __name__ == '__main__':
    main()
    
    
    
